home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / (Demos) / Quitter.c < prev    next >
C/C++ Source or Header  |  1995-06-10  |  4KB  |  82 lines

  1. /*
  2. Quitter.c
  3.  
  4. Kill a program on a local or remote computer by sending an AppleEvent.
  5.  
  6. Unfortunately, it appears that Apple doesn't consider active desk accessories as
  7. "processes" to which one can send an AppleEvent. The notes in KillEveryoneButMe.c
  8. indicate that the Finder can help out the AppleEvents mechanism for applications
  9. (and desk accessories?) that aren't apple-event aware by using "puppet strings".
  10. However, the KillEveryoneButMe.c notes indicate that puppet strings are only
  11. available if one identifies the target by Process Serial Number (PSN), i.e. one
  12. uses the typeProcessSerialNumber descriptor type, but the documentation of
  13. "Specifying a Target Address" in THINK Reference says that "to address an Apple
  14. event to a target on a remote computer on the network you must use either the
  15. typeSessionID or the typeTargetID descriptor type." Thus, to use puppet string we
  16. MUST use the PSN, but if the target is on a remote computer we CAN'T use the PSN.
  17. So apparently we can't use puppet strings on a remote computer.
  18.  
  19. At present this has nothing at all to do with the rest of the VideoToolbox, but
  20. David Brainard and I have been discussing the idea of a stand-alone VideoToolbox
  21. application that accepts AppleEvents commanding it to produce visual stimuli.
  22.  
  23. NOTE:
  24. It is essential that the isHighLevelEventAware bit be set in your application's SIZE resource,
  25. otherwise all your attempts to emit apple events will be ignored.
  26. In CodeWarrior, use the Edit:Preferences menu item to set the Project:SIZE Flags.
  27. In THINK C, use the menu item Project:SetProjectType:SIZE Flags.
  28.  
  29. SEE ALSO:
  30. VideoToolboxSources:KillEveryoneButMe.c. 
  31.  
  32. HISTORY:
  33. 3/5/93 dgp wrote it
  34. 3/9/93    dgp got it to work, by setting the HighLevelEvent-Aware bit, as instructed
  35. by Larry Harris, 76150,1027, a friendly fellow programmer on CompuServe.
  36. 4/17/93    dgp    #include VideoToolbox.h for PrintfExit().
  37. 12/15/93 dgp Go away quietly if user hits Cancel.
  38. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  39.             Metrowerks CodeWarrior C.
  40. 9/5/94 dgp removed assumption in printf's that int==short.
  41. 6/10/95 dgp added discussion of puppetstrings above.
  42. */
  43. #include "VideoToolbox.h"
  44. #include <stdio.h>
  45. #include <AppleEvents.h>
  46.  
  47. void main(void)
  48. {
  49.     int error;
  50.     unsigned char prompt[]="\pChoose a program to quit.";
  51.     PortInfoRec portInfo;
  52.     TargetID targetID;
  53.     AEAddressDesc target;
  54.     AppleEvent appleEvent;
  55.     AESendMode sendMode;
  56.     long value;
  57.  
  58.     MaximizeConsoleHeight();
  59.     printf("Welcome to Quitter.\n");
  60.     error=Gestalt(gestaltAppleEventsAttr,&value);
  61.     if(error || !(value&(1<<gestaltAppleEventsPresent)))PrintfExit("Sorry, I need AppleEvents.\n");
  62.     PPCInit();
  63.     // Select target through dialog with user.
  64.     error=PPCBrowser(prompt,NULL,0,&targetID.location,&portInfo,NULL,NULL);
  65.     if(error==-128)abort();    // User pressed Cancel.
  66.     if(error)PrintfExit("PPCBrowser error %d\n",error);
  67.     targetID.name=portInfo.name;
  68.     error=AECreateDesc(typeTargetID,(Ptr)&targetID,sizeof(targetID),&target);
  69.     if(error)PrintfExit("AECreateDesc error %d\n",error);
  70.     error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target
  71.         ,kAutoGenerateReturnID,kAnyTransactionID,&appleEvent);
  72.     if(error)PrintfExit("AECreateAppleEvent error %d\n",error);
  73.     error=AEDisposeDesc(&target);
  74.     sendMode=kAENoReply+kAENeverInteract+kAEDontReconnect;
  75.     error=AESend(&appleEvent,NULL,sendMode,kAENormalPriority
  76.         ,kAEDefaultTimeout,NULL,NULL);
  77.     if(error)PrintfExit("AESend error %d\n",error);
  78.     error=AEDisposeDesc(&appleEvent);
  79.     if(error)PrintfExit("AEDisposeDesc error %d\n",error);
  80.     printf("Done. “%s” has been asked to quit.\n",p2cstr(targetID.name.name));
  81. }
  82.